/**
 * @description Handle language
 */
import { addLocaleData } from 'react-intl'
import zh from 'react-intl/locale-data/zh'
import en from 'react-intl/locale-data/en'
import zhCN from 'antd/lib/locale-provider/zh_CN'
import enUS from 'antd/lib/locale-provider/en_US'

// Load more languages locale date
addLocaleData([...zh, ...en])

// TODO: Judge Language form url or browser or cookie
// Current language
let curLan = 'en'
// Has stored language
const storeLan = localStorage.getItem('ri-lan')
// Judge whether localStorage has ri-lan value
storeLan ? (curLan = storeLan) : localStorage.setItem('ri-lan', curLan)

const locale = curLan
const messages = require(`./${curLan}`)
const antdLocale = curLan === 'en' ? enUS : zhCN

export { locale, messages, antdLocale }
